<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script crossorigin="anonymous" src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.js"></script>
</head>
<body>
    <button>GET</button>
    <button>post</button>
    <button>ajax</button>
    <script>
        const btns = document.querySelectorAll('button');
        axios.defaults.baseURL = 'http://127.0.0.1:8000';
        btns[0].onclick = function() {
            //get请求
            axios.get('/axios-server',{
                //url参数
                params:{
                    id:100,
                    vip:7
                },
                //请求头信息
                headers:{
                    name:'atguigu',
                    age:10
                }
            }).then(value => {
                console.log(value);
            })
        };
        btns[1].onclick = function() {
            axios.post('/axios-server',{
                //url参数
                params:{
                    id:200,
                    vip:9
                },
                //请求头信息
                headers:{
                    height:180,
                    width:180
                },
                data:{
                    username:'admin',
                    password:'admin'
                }
            }).then(value => {
                console.log(value);
            }) 
        };
        btns[2].onclick = function() {
            axios({
                //请求方法
                method:'POST',
                //url
                url:'/axios-server',
                params:{
                    vip:10,
                    level:30
                },
                //头信息
                Headers:{
                    a:100,
                    b:200
                },
                //请求体参数
                data:{
                    username:'admin',
                    passward:'admin'
                },

            }).then(response => {
                console.log(response.status);
                console.log(response.statusText);
                console.log(response.headers);
            })
        };
    </script>
</body>
</html>